<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('测试用例列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12 search-collapse">
      <form id="formId">
        <input type="hidden" id="planId" name="planId" th:value="${plan.id}">
        <div class="select-list">
          <ul>
            <li>
              <label>名称：</label>
              <input type="text" name="name"/>
            </li>
            <li>
              <label>类型：</label>
              <select name="type" th:with="type=${@dict.getType('test_case_type')}">
                <option value="">所有</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
              </select>
            </li>
            <li>
              <label>模块id：</label>
              <input type="text" name="moduleId"/>
            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
              <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </li>
          </ul>
        </div>
      </form>
    </div>

    <div class="btn-group-sm" id="toolbar" role="group">

    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:case:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:case:remove')}]];
        var typeDatas = [[${@dict.getType('test_case_type')}]];
        var prefix = ctx + "system/plan/authCase";

        $(function() {
            var options = {
                url: prefix + "/unallocatedList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "测试用例",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'precondition',
                    title: '前置条件'
                },
                {
                    field: 'module.name',
                    title: '模块'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    field: 'updateBy',
                    title: '更新者'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="cancelAuthCase(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消授权</a> ');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        /* 分配用例-取消授权 */
		function cancelAuthCase(caseId) {
			$.modal.confirm("确认要移除用例吗？", function() {
				$.operate.post(prefix + "/cancel", { "planId": $("#planId").val(), "caseId": caseId });
		    })
		}

		/* 分配用例-选择用例 */
		function selectCase() {
			var url = prefix + '/selectCase/' + $("#planId").val();
		    $.modal.open("选择用例", url);
		}

		/* 添加用户-选择用例-提交 */
		function submitHandler() {
			var rows = $.table.selectFirstColumns();
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
			var data = { "planId": $("#planId").val(), "caseIds": rows.join() };
			$.operate.save(prefix + "/selectAll", data);
		}

    </script>
</body>
</html>